package com.ucar.dialog;

import java.util.ArrayList;

import com.ucar.R;
import com.ucar.adapter.AreaAdapter;
import com.ucar.bean.Area;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

/**
 * 选择数据dialog
 * @author moon
 *
 */
public class SelectAreaDialog extends BaseDialog 
{
	private Context mContext;
	private ListView lvData;
	private ArrayList<Area> areas;
	
	private OnCallBack mCallBack;
	
	public SelectAreaDialog( Context context, 
			ArrayList<Area> areas, OnCallBack mCallBack ) 
	{
		super(context);
		mContext = context;
		this.areas = areas;
		this.mCallBack = mCallBack;
	}

	@Override
	protected int getLayoutId() 
	{
		return R.layout.dialog_select_area;
	}

	@Override
	protected void initDialogViews() 
	{
		lvData = (ListView) findViewById( R.id.lv_data );
		AreaAdapter mAdapter = new AreaAdapter( mContext );
		lvData.setAdapter( mAdapter );
		
		mAdapter.add( areas, true );
	}

	@Override
	protected void afterDialogViews() 
	{
		lvData.setOnItemClickListener( new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, 
					View view, int position, long id ) 
			{
				if( mCallBack != null )
				{
					mCallBack.onSelected( position );
				}
				SelectAreaDialog.this.dismiss();
			}
		});
	}

	public interface OnCallBack
	{
		public void onSelected( int position );
	}
}
